<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTransactionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_transactions', function (Blueprint $table) {
            //用户消费记录
            $table->bigIncrements('id');
            $table->bigInteger('seller_id')->unsigned()->nullable(false)->comment('商家id');
            $table->bigInteger('user_id')->unsigned()->nullable(false)->comment('用户id');
            $table->decimal('price', 9, 2)->nullable(false)->default(0.00)->comment('实收金额');
            $table->decimal('amount', 9, 2)->nullable(false)->default(0.00)->comment('金额');
            $table->string('sn',255)->unique()->nullable(false)->comment('编号');
            $table->string('desc',255)->nullable(false)->comment('备注说明');
            $table->unsignedTinyInteger('type')->nullable(false)->default(1)->comment('1-充值2-购物');
            $table->timestamps();
            $table->foreign('seller_id')->references('id')->on('sellers')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_transactions');
    }
}
